<template>
    <h1>猜数字练习</h1>
    <input type="text" v-model="guess">
    <button @click="check">检查</button>
    <h3>{{result}}</h3>
</template>

<script setup>
import { ref } from 'vue';

const guess = ref('')
const result = ref('')

const num = Math.floor(Math.random() * 100) + 1
console.log(num)

const check = () => {
    const g = Number(guess.value)
    if (g === num) {
        result.value = '恭喜你，猜对了！'
    } else if(g < num) {
        result.value = '很遗憾，猜小了！'
    }else{
        result.value = '很遗憾，猜大了！'
    }
}
</script>

<style scoped>

</style>